<template>
    <div class="common-page page-corp-company" v-loading.fullscreen="loading">
        <div class="common-page__head">
            <comp-paths class="route" :paths="['/corp', '/corp/companys', $route.fullPath]"></comp-paths>
            <div class="title" v-if="company">
                <div class="text">{{ company.name }}</div>
            </div>
            <div class="title" v-else></div>
        </div>
        <comp-tabs class="common-page__head" :tabs="[$route.fullPath, '/corp/company/orders?companyId=' + companyId, '/corp/company/products?companyId=' + companyId, '/corp/company/demands?companyId=' + companyId, '/corp/company/attendances?companyId=' + companyId]"></comp-tabs>
        <div class="common-page__body common-form" v-if="company">
            <div class="rows">
                <div class="row row--head">
                    <div class="name">基本信息</div>
                    <div class="value"></div>
                </div>
                <div class="row">
                    <div class="name">{{ company.typeText }}名称</div>
                    <div class="value">{{ company.name }}</div>
                </div>
                <div class="row">
                    <div class="name">{{ company.typeText }}简介</div>
                    <div class="value">
                        <span class="button" @click="action('company-desc', true)">查看</span>
                    </div>
                </div>
                <div class="row">
                    <div class="name">法定代表人</div>
                    <div class="value">{{ company.owner }}</div>
                </div>
                <div class="row">
                    <div class="name">{{ company.typeText }}规模</div>
                    <div class="value">{{ company.sizeText }}</div>
                </div>
                <div class="row">
                    <div class="name">所在地区</div>
                    <div class="value">{{ company.city.name + company.county.name }}</div>
                </div>
                <div class="row">
                    <div class="name">详细地址</div>
                    <div class="value">
                        <span class="text">{{ company.location.address }}</span>
                        <a class="button" :href="company.location.link" target="_blank" v-if="company.location.lng > 0 && company.location.lat > 0">查看</a>
                    </div>
                </div>
                <div class="row">
                    <div class="name">所属行业</div>
                    <div class="value">{{ company.industry.name }}</div>
                </div>
                <div class="row">
                    <div class="name">所属分类</div>
                    <div class="value">{{ company.tag.name }}</div>
                </div>
                <div class="row">
                    <div class="name">资格认定</div>
                    <div class="value">
                        <span class="text" v-if="company.cert01 === 'yes'">高新技术企业</span>
                        <span class="text" v-if="company.cert02 === 'yes'">单项冠军企业</span>
                        <span class="text" v-if="company.cert03 === 'yes'">国家级专精特新小巨人企业</span>
                        <span class="text" v-if="company.cert04 === 'yes'">自治区级专精特新小巨人企业</span>
                        <span class="text" v-if="company.cert05 && company.cert05 !== 'not'">制造业创新中心（{{ company.cert05Text }}）</span>
                        <span class="text" v-if="company.cert06 && company.cert06 !== 'not'">企业技术中心（{{ company.cert06Text }}）</span>
                    </div>
                </div>
<!--                <div class="row">-->
<!--                    <div class="name" style="height: auto; min-height: 20px">主管工作队</div>-->
<!--                    <div class="value">-->
<!--                        <span class="text" v-for="dept in company.depts" :key="dept.id">{{ dept.name }}</span>-->
<!--                    </div>-->
<!--                </div>-->
                <div class="row">
                    <div class="name">最近走访</div>
                    <div class="value">
                        <span v-if="company.attendance.id">{{ company.attendance.client.name }}</span>
                        <span style="margin-left: 0.5em; color: #aaa" v-if="company.attendance.id">{{ company.attendance.startAt }}</span>
                    </div>
                </div>
                <div class="row">
                    <div class="name">事项统计</div>
                    <div class="value">
                        <span>共 {{ company.stats.ordersTotal }} 项</span>
                        <span style="margin-left: 0.5em; color: #aaa">未办结 {{ company.stats.ordersFinishedNotTotal }} 项</span>
                    </div>
                </div>
                <div class="row">
                    <div class="name">添加时间</div>
                    <div class="value">{{ company.createdAt }}</div>
                </div>
                <div class="row">
                    <div class="name">社会信用统一代码</div>
                    <div class="value">{{ company.xydm }}</div>
                </div>
                <div class="row">
                    <div class="name">服务小组</div>
                    <div class="value">{{ company.fwxz }}</div>
                </div>
                <div class="row row--picture">
                    <img class="value" :src="company.logo.short" v-if="company.logo.id" />
                    <img class="value" :src="require('../assets/company-avatar.png')" v-else />
                </div>
            </div>
            <div class="rows">
                <div class="row row--head">
                    <div class="name">联系人信息</div>
                    <div class="value"></div>
                </div>
                <div class="row row--2x">
                    <div class="value">
                        <el-table size="medium" border :data="company.employees">
                            <el-table-column label="姓名/手机号" min-width="6">
                                <template #default="scope">
                                    <span>{{ scope.row.client.name }}</span>
                                    <span style="margin-left: 0.5em; color: #aaa">{{ scope.row.client.mobile }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="职务" min-width="4">
                                <template #default="scope">{{ scope.row.duty }}</template>
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
            </div>
            <div class="rows">
                <div class="row row--head">
                    <div class="name" style="width: auto">服务专员信息</div>
                    <div class="value"></div>
                </div>
                <div class="row row--2x">
                    <div class="value">
                        <el-table size="medium" border :data="company.helpers">
                            <el-table-column label="姓名/手机号" min-width="8">
                                <template #default="scope">
                                    <span>{{ scope.row.client.name }}</span>
                                    <span style="margin-left: 0.5em; color: #aaa">{{ scope.row.client.mobile }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="所属部门及担任职务" min-width="16">
                                <template #default="scope">
                                    <div v-for="depment in scope.row.client.depments" :key="depment.id">
                                        <span>{{ depment.dept.name }}</span>
                                        <span> - </span>
                                        <span>{{ depment.duty }}</span>
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
            </div>
        </div>
         <!--  -->
        <div class="common-page__foot" v-if="profile.role !=='officer' || profile.isAdmin ==='1'">
            <el-button type="warning" size="small" icon="el-icon-setting" @click="setCompany()">信息维护</el-button>
        </div>
        <comp-dialog title="企业/项目简介" width="600px" height="80vh" ref="companyDesc">
            <comp-html-editor style="height: 100%" ref="companyDescEditor" :content="company.desc" v-if="company">
                <template #foot="scope">
                    <el-button type="plain" size="small" icon="el-icon-close" @click="action('company-desc', false)">关闭</el-button>
                </template>
            </comp-html-editor>
        </comp-dialog>
        <comp-dialog title="编辑企业/项目" ref="companySetForm">
            <el-form size="small" label-width="140px" style="margin-right: 20px" @submit.native.prevent v-if="companySetForm">
                <!-- <el-form-item label="企业/项目LOGO：">
                    <img style="display: block; margin: 0 10px 10px 0; max-width: 120px; height: 60px; object-fit: cover" :src="companySetForm.logo.short" v-if="companySetForm.logo.id" />
                    <el-button type="plain" icon="el-icon-plus" @click="setCompany('upload-logo')">{{ companySetForm.logo.id ? "更换图片" : "选择图片" }}</el-button>
                </el-form-item> -->
                <el-form-item label="企业/项目名称：" required>
                    <el-input ref="companySetFormName" v-model="companySetForm.name" style="width: 480px" placeholder="请输入" :maxlength="100" :readonly="loading" @change="setCompany('validate')"></el-input>
                </el-form-item>
                <el-form-item label="企业/项目简介：">
                    <el-input type="textarea" v-model="companySetForm.desc" style="width: 480px" placeholder="请输入" :maxlength="1000" :rows="4" resize="none" :readonly="loading" @change="setCompany('validate')"></el-input>
                </el-form-item>
                <el-form-item label="所在地址：" required>
                    <el-select v-model="companySetForm.city.id" style="margin-right: 10px; width: 230px" placeholder="城市" disabled @change="setCompany('validate')">
                        <template v-for="data in citys">
                            <el-option :key="data.id" :label="data.name" :value="data.id" v-if="data.province.id === companySetForm.province.id"></el-option>
                        </template>
                    </el-select>
                    <el-select v-model="companySetForm.county.id" style="width: 240px" placeholder="县区" @change="setCompany('validate')">
                        <template v-for="data in countys">
                            <el-option :key="data.id" :label="data.name" :value="data.id" v-if="data.city.id === companySetForm.city.id"></el-option>
                        </template>
                    </el-select>
                    <div style="margin-top: 10px"></div>
                    <el-input v-model="companySetForm.location.address" style="width: 480px" placeholder="详细地址" :maxlength="100" :readonly="loading" @change="setCompany('validate')"></el-input>
                </el-form-item>
                <el-form-item label="地址坐标：">
                    <el-input v-model="companySetForm.location.coord" style="width: 392px" placeholder="请输入" :readonly="loading" @change="setCompany('validate')"></el-input>
                    <el-tag style="margin-left: 10px" disable-transitions>
                        <span>坐标拾取</span>
                        <a style="position: absolute; top: 0; left: 0; width: 100%; height: 100%" href="https://lbs.qq.com/tool/getpoint/index.html" target="_blank"></a>
                    </el-tag>
                </el-form-item>
                <el-form-item label="法定代表人：">
                    <el-input v-model="companySetForm.owner" style="width: 480px" placeholder="请输入" :maxlength="100" :readonly="loading" @change="setCompany('validate')"></el-input>
                </el-form-item>
                <el-form-item label="企业/项目规模：">
                    <el-select v-model="companySetForm.size" style="width: 480px" placeholder="请选择" @change="setCompany('validate')">
                        <el-option v-for="data in env.companySizes" :key="data.id" :label="data.name" :value="data.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="所属行业：">
                    <el-input v-model="companySetForm.industry.name" style="width: 480px" placeholder="请输入" :maxlength="100" :readonly="loading" @change="setCompany('validate')"></el-input>
                </el-form-item>
                <el-form-item label="所属分类：">
                    <el-select v-model="companySetForm.tag.id" style="width: 480px" placeholder="请选择" @change="setCompany('validate')">
                        <el-option v-for="data in tags" :key="data.id" :label="data.name" :value="data.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="联系人：">
                    <el-tag style="margin-right: 10px; max-width: 351px" disable-transitions v-if="companySetForm.employees.length > 0">{{ companySetForm.employees.map((employee) => employee.client.name).join("、") }}</el-tag>
                    <el-button type="plain" icon="el-icon-plus" @click="setCompany('pick-employees-start')">编辑联系人</el-button>
                </el-form-item>
                <el-form-item label="服务专员信息：">
                    <el-tag style="margin-right: 10px; max-width: 351px" disable-transitions v-if="companySetForm.helpers.length > 0 && selectopen">{{ companySetForm.helpers.map((helper) => helper.client.name).join("、") }}</el-tag>
                    <el-tag style="margin-right: 10px; max-width: 351px" disable-transitions v-if="companySetForm.helpers.length > 0 && !selectopen">{{ companySetForm.helpers.map((helper) => helper.user_name).join("、") }}</el-tag>

                    <el-button type="plain" icon="el-icon-plus" @click="setCompany('pick-helpers-start')">选择服务专员</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-check" @click="setCompany('submit')">保存</el-button>
                    <el-button type="plain" icon="el-icon-close" @click="setCompany('end')">放弃</el-button>
                </el-form-item>
            </el-form>
        </comp-dialog>
        <comp-dialog title="编辑联系人" ref="companyEmployees">
            <el-form size="small" label-width="98px" style="margin-right: 20px" @submit.native.prevent v-if="companySetForm">
                <el-form-item v-for="(employee, index) in employees" :key="index" :label="'联系人' + (index + 1) + '：'">
                    <el-input v-model="employee.client.name" style="margin-right: 10px; width: 120px" placeholder="姓名" :maxlength="100" :readonly="loading" @change="setCompany('pick-employees-validate')"></el-input>
                    <el-input v-model="employee.client.mobile" style="margin-right: 10px; width: 160px" placeholder="手机号" :maxlength="100" :readonly="loading" @change="setCompany('pick-employees-validate')"></el-input>
                    <el-input v-model="employee.duty" style="margin-right: 10px; width: 160px" placeholder="担任职务" :maxlength="100" :readonly="loading" @change="setCompany('pick-employees-validate')"></el-input>
                    <el-button type="plain" icon="el-icon-delete" @click="setCompany('pick-employees-delete', employee)"></el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-check" @click="setCompany('pick-employees-submit')">完成</el-button>
                    <el-button type="plain" icon="el-icon-close" @click="setCompany('pick-employees-end')">取消</el-button>
                </el-form-item>
            </el-form>
        </comp-dialog>
    <comp-dialog title="选择服务专员" ref="companyHelpers">
            <el-form size="small" label-width="84px" style="margin-right: 20px;" @submit.native.prevent v-if="company">
                <el-form-item label-width="1" style="margin-bottom: 80px">
                    <div style="min-width: 320px; max-width: 520px;height:500px">


                    <el-input class="filter" v-model="keyword" size="small" style="width: 320px" clearable placeholder="请输入" :readonly="loading" @keyup.enter="handleQuery">
                        <span slot="prepend">联络员名称</span>
                    </el-input>
                        <el-button class="filter" type="primary" size="small" @click="handleQuery()">查询</el-button>

                    <el-table re size="medium" height="100%" :data="deepts" @header-click="onTableHeaderClick" @row-click="onTableRowClick" @selection-change="onTableSelectionChange">
                        <el-table-column type="selection" align="center"></el-table-column>
                        <el-table-column prop="user_name" label="联络员/账号" width="auto" min-width="120" />
                        <el-table-column prop="user_role" label="角色" width="auto" min-width="120" />

                    </el-table>
                    <div style="">
                       
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page.sync="pageNum"
                            :page-sizes="[100, 200, 300, 400]"
                            :page-size="pageSize"
                            layout="sizes, prev, pager, next"
                            :total="total">
                        </el-pagination>

                    </div>

                    </div>
                </el-form-item>
                <el-form-item label-width="1">
                    <el-button type="primary" icon="el-icon-check" @click="addCompany('pick-helpers-submit')">完成</el-button>
                    
                </el-form-item>
            </el-form>
        </comp-dialog>
    </div>
</template>

<script>
    import mixin from "../mixin";
    import { string, int, float, deepCopy, selectFile, cache } from "../util";
    export default {
        name: "page-corp-company",
        title: "企业/项目详情",
        nodes: ["/menu/corp"],
        childs: [],
        mixins: [mixin],
        data: () => ({
            loading: false,
            companyId: "",
            company: null,
            companySetForm: null,
            keyword:null,
            citys: [],
            countys: [],
            tags: [],
            employees: [],
            helpers: [],
            depts: [],
            deepts:[],
            pageSize:100,
            pageNum:1,
            self: false,
            total:0,
            selectopen:true,
            selected:[],
            fwzyid:[],
            abc:false,
        }),
        methods: {
            addCompany(){
                    this.$refs.companyHelpers.close();
                    this.selectopen = false
                    this.companySetForm.helpers = this.selected;
                    console.log(this.companySetForm.helpers);
                
            },
            action(name, data) {
                if (this.loading) return;
                if (name === "company-desc") {
                    if (data) {
                        this.$refs.companyDesc.init();
                        this.$nextTick(() => this.$refs.companyDescEditor.init());
                    } else {
                        this.$refs.companyDescEditor.destroy();
                        this.$refs.companyDesc.close();
                    }
                }
            },
            
            handleQuery(){
                this.plugins.user.getOrderDeptDepmentskeyWord(this.keyword).then(res =>{
                            if (res.code === 0) this.deepts = res.data;this.total = res.total
                            });
            },
               handleSizeChange(val){
                this.pageSize = val
                this.getlianList(this.pageSize,this.pageNum)
            },
             handleCurrentChange(val){
                this.pageNum =val
                this.getlianList(this.pageSize,this.pageNum)
            },
                   onTableHeaderClick() {
                // this.select && this.$refs.table.toggleAllSelection();
            },
            onTableRowClick(row) {
                // this.select && this.$refs.table.toggleRowSelection(row);
            },
            onTableLinageChange(value) {
                // this.filters.linage = value;
                // this.search(true);
            },
            onTablePageChange(value) {
                // this.filters.page = value;
                // this.search(true);
            },
            onTableSelectionChange(selects) {
                console.log(selects);
                this.selected = selects
                // this.filters.ids = selects.map((data) => data.id);
                // this.selects = selects;
            },
               getlianList(a,b){
                     this.plugins.user.getOrderDeptDepmentsObjectss(a,b).then(res =>{
                            if (res.code === 0) this.deepts = res.data;this.total = res.total
                            });
            },
            setCompany(action, data) {
                if (this.loading) return;
                let form = this.companySetForm;
                let citys = this.citys;
                let countys = this.countys;
                let tags = this.tags;
                let depts = this.depts;
                let profile = this.profile;
                if (!action || action === "start") {
                    this.loading = true;
                    this.plugins.user.call(async () => {
                        if (tags.length > 0) return { code: 0 };
                        let res = await this.plugins.user.getCompanyOfTags();
                        if (res.code === 0) this.tags = res.data;
                        return res;
                    }).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            this.companySetForm = deepCopy(this.company);
                            
                            this.setCompany("validate");
                            this.$refs.companySetForm.init();
                            this.$nextTick(() => this.$refs.companySetFormName.focus());
                        } else {
                            this.plugins.modal.toast("加载失败<br>" + res.code + "：" + res.msg, "error");
                        }
                    });
                } else if (action === "validate") {
                    let error = "";
                    form.type = form.type || this.env.companyTypes[0].value;
                    form.name = string(form.name).trim();
                    error = error || (form.name ? "" : "请输入企业/项目名称！");
                    form.desc = string(form.desc);
                    form.city.id = string(() => citys.find((city) => city.id === form.city.id && city.province.id === form.province.id).id);
                    form.county.id = string(() => countys.find((county) => county.id === form.county.id && county.city.id === form.city.id).id);
                    error = error || (form.province.id && form.city.id && form.county.id ? "" : "请完善所在地址！");
                    form.location.address = string(form.location.address).trim();
                    form.location.coord = string(form.location.coord).trim();
                    form.location.lng = Math.min(Math.max(float(form.location.coord.split(",")[1], 6), 0), 180);
                    form.location.lat = Math.min(Math.max(float(form.location.coord.split(",")[0], 6), 0), 90);
                    form.location.coord = form.location.lng > 0 && form.location.lat > 0 ? form.location.lat + "," + form.location.lng : "";
                    form.owner = string(form.owner).trim();
                    // error = error || (form.helpers.length > 0 ? "" : "请选择服务专员！");
                    form.status = form.status || this.env.companyStatus[0].value;
                    if (data) this.plugins.modal.toast(error, "error");
                    return !error;
                } else if (action === "upload-logo") {
                    if (!data) return selectFile("image/*").then((file) => {
                        if (file.size > 5 * 1048576) this.plugins.modal.toast("图片过大，不能大于5MB哦！请重新选择。", "error");
                        else this.setCompany(action, file);
                    });
                    let timer = null;
                    let progress = (event) => timer = clearTimeout(timer) || setTimeout(() => this.plugins.modal.toast("上传进度：" + event.percent + "%", "info"), 200);
                    this.loading = true;
                    this.plugins.user.uploadFile(data, "image", progress).then((res) => {
                        this.loading = false;
                        if (res.code === 0) {
                            form.logo = res.data;
                            this.setCompany("validate");
                        } else {
                            this.plugins.modal.alert("图片上传失败", res.code + "：" + res.msg, "error");
                        }
                    });
                } else if (action === "pick-employees-start") {
                    let employees = deepCopy(form.employees);
                    while (employees.length < 5) employees.push(this.plugins.user.formatEmployee());
                    this.employees = employees;
                    this.$refs.companyEmployees.init();
                } else if (action === "pick-employees-validate") {
                    let employees = this.employees;
                    let error = "";
                    for (let employee of employees) {
                        let index = employees.indexOf(employee);
                        let name = employee.client.name = string(employee.client.name).trim();
                        let mobile = employee.client.mobile = string(employee.client.mobile).trim();
                        let duty = employee.duty = string(employee.duty).trim();
                        if (name || mobile || duty) {
                            error = error || (name ? "" : "请输入联系人" + (index + 1) + "的姓名！");
                            error = error || (mobile ? "" : "请输入联系人" + (index + 1) + "的手机号！");
                            error = error || (/^1[3-9]\d{9}$/.test(mobile) ? "" : "联系人" + (index + 1) + "的手机号格式不正确！");
                            error = error || (duty ? "" : "请输入联系人" + (index + 1) + "的担任职务！");
                        }
                    }
                    if (data) this.plugins.modal.toast(error, "error");
                    return !error;
                } else if (action === "pick-employees-delete") {
                    let employee = data;
                    employee.client.id = "";
                    employee.client.name = "";
                    employee.client.mobile = "";
                    employee.duty = "";
                } else if (action === "pick-employees-submit") {
                    if (!this.setCompany("pick-employees-validate", true)) return;
                    form.employees = this.employees.filter((employee) => employee.client.name || employee.client.mobile || employee.duty);
                    this.setCompany("pick-employees-end");
                    this.setCompany("validate");
                } else if (action === "pick-employees-end") {
                    this.$refs.companyEmployees.close();
                } else if (action === "pick-helpers-start") {
                    this.abc =true
                    this.loading = true;
                    this.plugins.user.call(async () => {
                        this.getlianList(this.pageSize,this.pageNum)
                        if (depts.length > 0) return;
                        for (let depment of profile.depments) {
                            if (!form.depts.some((dept) => dept.id === depment.dept.id)) continue;
                            let dept = depment.dept;
                            let res = await this.plugins.user.getOrderDeptDepments(dept);
                            if (res.code === 0) dept.depments = res.data.filter((depment) => depment.client.banned === "not");
                            if (res.code === 0) depts.push(dept);
                        }
                    }, async () => {
                        for (let dept of depts) {
                            for (let depment of dept.depments) {
                                depment.dept.id = dept.id;
                                depment.dept.name = dept.name;
                                depment.selected = form.helpers.some((helper) => helper.client.id === depment.client.id);
                            }
                        }
                    }).then(() => {
                        this.loading = false;
                        this.$refs.companyHelpers.init();
                    });
                } else if (action === "pick-helpers-submit") {
                    depts.forEach((dept) => dept.depments.forEach((depment) => {
                        if (depment.selected) {
                            if (form.helpers.some((helper) => helper.client.id === depment.client.id)) return;
                            let helper = this.plugins.user.formatHelper();
                            helper.client.id = depment.client.id;
                            helper.client.name = depment.client.name;
                            form.helpers.push(helper);
                        } else {
                            let index = form.helpers.findIndex((helper) => helper.client.id === depment.client.id);
                            if (index > -1) form.helpers.splice(index, 1);
                        }
                    }));
                    this.setCompany("pick-helpers-end");
                    this.setCompany("validate");
                } else if (action === "pick-helpers-end") {
                    this.$refs.companyHelpers.close();
                } else if (action === "submit") {
                    if (!this.setCompany("validate", true)) return;
                    this.loading = true;
                     if(this.abc){
                         
                         form.helpers = this.selected;
                            //  form.helpers =this.companySetForm.helpers


                        }else{
                        
                             form.helpers =this.companySetForm.helpers
                        }
                    this.plugins.user.setCompany(form).then((res) => {
                        console.log(form);
                       
                        this.loading = false;
                        if (res.code === 0) {
                            
                            this.plugins.modal.toast("保存成功！", "success");
                            this.selectopen =true;
                             this.companySetForm = deepCopy(this.company);
                            this.setCompany("end");
                            this.init();
                        } else {
                            this.plugins.modal.alert("保存失败", res.code + "：" + res.msg, "error");
                        }
                    });
                } else if (action === "end") {
                    this.$refs.companySetForm.close();
                }
            },
            destroy() {
                if (this.loading) return;
                return true;
            },
            init() {
                console.log(this.profile);
                if (this.loading) return;
                let query = this.$route.query;
                let company = null;
                this.loading = true;
                this.companyId = query.companyId;
                this.company = cache(query.companyId);
                this.$root.$refs.navbar.init();
                this.plugins.user.call(async () => {
                    let res = await this.plugins.user.init();
                    if (res.code === 0) { }
                    return res;
                }, async () => {
                    if (this.access(this.$route.name)) return { code: 0 };
                    return this.env.xhrErrors.find((error) => error.code === 4);
                }, async () => {
                    let res = await this.plugins.user.getCompany(query.companyId);
                    if (res.code === 0) company = res.data;
                    return res;
                }).then((res) => {
                    this.loading = false;
                    this.$root.$refs.navbar.init();
                    if (res.code === 0) {
                        this.company = cache(query.companyId, company);
                        this.citys = this.plugins.user.citys;
                        this.countys = this.plugins.user.countys;
                       
                        this.self = this.company.depts.some((dept) => this.profile.depments.some((depment) => depment.dept.id === dept.id));
                    } else if (res.code === 2) {
                        this.$root.$refs.navbar.login();
                    } else {
                        this.plugins.modal.alert("页面加载失败", res.code + "：" + res.msg, "error").then(() => this.$router.replace("/corp/companys"));
                    }
                });
            },
        },
       
    };
</script>

<style lang="scss">
    .page-corp-company {
        overflow: hidden;
    }
</style>